
import 'package:boss/main.dart';
import 'package:boss/models/offers.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';

class OffersType {
  static final int processing = 1;
  static final int noStarted = 2;
  static final int over = 3;

  static final Map<int, String> int2String = {
    1: '进行中',
    2: '未开始',
    3: '已结束',
  };
}

class OffersProvider extends ChangeNotifier {
  Map<int, List<Offers>> offers = {
    1: null,
    2: null,
    3: null,
  };

  Future<bool> initData(int status) async {
    try {
      var response = await api.queryStoreDiscountByStatus(status);
      if (!response.successful()) {
        return false;
      }

      offers[status] = response.data;
      notifyListeners();

      return true;
    } catch (e) {
      toast(e.toString());
      return false;
    } finally {}
  }

  backstageRefresh() {
    offers.forEach((status, data) {
      if (data != null) {
        initData(status);
      }
    });
  }
}
